using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;

using WHC.Pager.Entity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Carmall.Entity;
using Carmall.IDAL;

namespace Carmall.DAL
{
    /// <summary>
    /// Users 的摘要说明。
    /// </summary>
    public class Users : BaseDAL<UsersInfo>, IUsers
    {
        #region 对象实例及构造函数

        public static Users Instance
        {
            get
            {
                return new Users();
            }
        }
        public Users()
            : base("users", "UserID")
        {
        }

        #endregion

        /// <summary>
        /// 将DataReader的属性值转化为实体类的属性值，返回实体类
        /// </summary>
        /// <param name="dr">有效的DataReader对象</param>
        /// <returns>实体类对象</returns>
        protected override UsersInfo DataReaderToEntity(IDataReader dataReader)
		{
			UsersInfo usersInfo = new UsersInfo();
			SmartDataReader reader = new SmartDataReader(dataReader);
			
			
			usersInfo.UserID = reader.GetInt64("UserID");
			usersInfo.Username = reader.GetString("Username");
			usersInfo.Password = reader.GetString("Password");
			usersInfo.UserType = reader.GetInt32("UserType");
            usersInfo.ParentID = reader.GetInt64("ParentID");
			usersInfo.Name = reader.GetString("Name");
			usersInfo.Role = reader.GetInt32("Role");
			usersInfo.Tel = reader.GetString("Tel");
			usersInfo.BirthDay = reader.GetDateTime("BirthDay");
			usersInfo.Email = reader.GetString("Email");
			usersInfo.Address = reader.GetString("Address");
			usersInfo.Notes = reader.GetString("Notes");

			
			return usersInfo;
		}

        /// <summary>
        /// 将实体对象的属性值转化为Hashtable对应的键值
        /// </summary>
        /// <param name="obj">有效的实体对象</param>
        /// <returns>包含键值映射的Hashtable</returns>
        protected override Hashtable GetHashByEntity(UsersInfo obj)
        {
            UsersInfo info = obj as UsersInfo;
            Hashtable hash = new Hashtable();


            hash.Add("UserID", TypeHelper.SafeInt(info.UserID));
            hash.Add("Username", TypeHelper.SafeString(info.Username));
            hash.Add("Password", TypeHelper.SafeString(info.Password));
            hash.Add("UserType", TypeHelper.SafeInt(info.UserType));
            hash.Add("ParentID", TypeHelper.SafeInt(info.ParentID));
            hash.Add("Name", TypeHelper.SafeString(info.Name));
            hash.Add("Role", TypeHelper.SafeInt(info.Role));
            hash.Add("Tel", TypeHelper.SafeString(info.Tel));
            hash.Add("BirthDay", TypeHelper.SafeTime(info.BirthDay));
            hash.Add("Email", TypeHelper.SafeString(info.Email));
            hash.Add("Address", TypeHelper.SafeString(info.Address));
            hash.Add("Notes", TypeHelper.SafeString(info.Notes));


            return hash;
        }
    }
}